
#include <cassert>
#include <iostream>
#include <memory>
#include <vector>
using namespace std;

class A {
public:
  int **a;

public:
  A(int v) {
    a = new int *;
    *a = new int[3];
    // a[0] = new int; // 也可以
    a[0][0] = v;
    a[0][1] = v * 2;
    a[0][2] = v * 3;
  }
  int *const *data() const { return a; }

  void setData(int b) const { a[0][1] = b; }
};

class B {
public:
  shared_ptr<vector<int *>> a;

public:
  B(int v) {
    a = make_shared<vector<int *>>(3);
    // a->resize(3);
    // a[0] = new int; // 也可以
    (*a)[0] = new int{v};
    (*a)[1] = new int{v * 2};
    (*a)[2] = new int{v * 3};
  }
  int *const *data() const { return (*a).data(); }

  void setData(int b) const { *((*a)[1]) = b; }
  void print() {
    cout << *((*a)[0]) << "  " << *((*a)[1]) << "  " << *((*a)[2]) << endl;
  }
};

int main() {
  A a(1);
  int *const *b = a.data();
  cout << **b << endl;
  a.setData(8);
  cout << a.a[0][0] << a.a[0][1] << a.a[0][2] << endl;
  B bt(3);
  bt.setData(2);
  bt.print();
  return 0;
}